//
//  LTFTopicCell.m
//  NeteaseNews
//
//  Created by liutaifeng on 16/4/18.
//  Copyright © 2016年 liutaifeng. All rights reserved.
//

#import "LTFTopicCell.h"
#import "IsNight.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height
@implementation LTFTopicCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    
    //背景
    self.background = [[UIView alloc] init];
    [self.contentView addSubview:self.background];
    [_background release];
    //self.background.backgroundColor = [UIColor blueColor];
    //背景图
    self.backgroundImageView = [[UIImageView alloc] init];
    [self.background addSubview:self.backgroundImageView];
    //self.backgroundImageView.backgroundColor = [UIColor blackColor];
    [_backgroundImageView release];
    //图片
    self.picImageView = [[UIImageView alloc] init];
    [self.background addSubview:self.picImageView];
    //self.picImageView.backgroundColor = [UIColor redColor];
    [_picImageView release];
    
    //头像底
    self.headBackgroundImageView = [[UIImageView alloc] init];
    [self.background addSubview:self.headBackgroundImageView];
    [_headBackgroundImageView release];
    self.headBackgroundImageView.backgroundColor = [UIColor whiteColor];
    //头像
    self.headImageView = [[UIImageView alloc] init];
    [self.background addSubview:self.headImageView];
    [_headImageView release];
    //self.headImageView.backgroundColor = [UIColor yellowColor];
    //内容
    self.contentLabel = [[UILabel alloc] init];
    [self.background addSubview:self.contentLabel];
    //self.contentLabel.backgroundColor = [UIColor whiteColor];
    [_contentLabel release];
    
    
    
    //名字
    self.nameAndJobLabel = [[UILabel alloc] init];
    [self.background addSubview:self.nameAndJobLabel];
   // self.nameAndJobLabel.backgroundColor = [UIColor redColor];
    [_nameAndJobLabel release];
    
    
    
    //类别, 关注和提问数
    self.sortAttentionAndQuestionLabel = [[UILabel alloc] init];
    [self.background addSubview:self.sortAttentionAndQuestionLabel];
    //self.sortAttentionAndQuestionLabel.backgroundColor = [UIColor redColor];
    [_sortAttentionAndQuestionLabel release];
    
    
    //关注按钮
    self.attentionButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.background addSubview:self.attentionButton];
    self.attentionButton.backgroundColor = [UIColor redColor];
        self.attentionButton.tintColor = [UIColor whiteColor];
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if ([IsNight nowIsNight]) {
        self.contentView.backgroundColor = [IsNight nightColor];
        _nameAndJobLabel.textColor = [IsNight textNightColor];
        _sortAttentionAndQuestionLabel.textColor = [IsNight textNightColor];
        _contentLabel.textColor = [IsNight textNightColor];
    }
    else {
        self.contentView.backgroundColor = [UIColor whiteColor];
        _nameAndJobLabel.textColor = [UIColor blackColor];
        _sortAttentionAndQuestionLabel.textColor = [UIColor blackColor];
        _contentLabel.textColor = [UIColor blackColor];
    }
    self.background.frame = CGRectMake(10, 10, WIDTH - 20, HEIGHT - 20);
    self.backgroundImageView.frame = self.background.bounds;
    self.headImageView.frame = CGRectMake(10, 20, 50, 50);
    self.headImageView.layer.cornerRadius = 25;
    self.headImageView.layer.masksToBounds = YES;
    self.headBackgroundImageView.frame = CGRectMake(20, 20, 58, 58);
    self.headBackgroundImageView.layer.cornerRadius = 29;
    self.headBackgroundImageView.layer.masksToBounds = YES;
    self.headBackgroundImageView.center = self.headImageView.center;
    
    self.nameAndJobLabel.frame = CGRectMake(80, 20, WIDTH / 2, 25);
    
    self.picImageView.frame = CGRectMake(2, 48, WIDTH - 24, HEIGHT / 2 - 10);
    
    self.contentLabel.frame = CGRectMake(10, HEIGHT / 2 + 45, WIDTH - 40, 25);
    self.contentLabel.numberOfLines = 0;
    [self.contentLabel sizeToFit];
    
    
    self.sortAttentionAndQuestionLabel.frame = CGRectMake(10, HEIGHT / 2 + 100, WIDTH / 2 + 30, 20);
    
    
    
    
    self.attentionButton.frame = CGRectMake(WIDTH / 4 * 3 - 30, HEIGHT / 2 + 90, WIDTH / 4, 40);
    [self.attentionButton setTitle:@"+ 关注" forState:UIControlStateNormal];
    self.attentionButton.layer.cornerRadius = 20;
    

    

    
}


- (void)dealloc {
    [_headBackgroundImageView release];
    [_headImageView release];
    [_background release];
    [_backgroundImageView release];
    [_picImageView release];
    [_contentLabel release];
    [_nameAndJobLabel release];
    [_sortAttentionAndQuestionLabel release];
    [_attentionButton release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
